package com.itheima.mm.controller;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.itheima.mm.dto.CompanDto;
import com.itheima.mm.pojo.Company;
import com.itheima.mm.pojo.PageResult;
import com.itheima.mm.pojo.Result;
import com.itheima.mm.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * heimamm
 *
 * @ClassName CompanyController
 * @Description
 * @Author 吴志强 --游侠波克比
 * @Date 2022/1/10 15:17
 * @Version V1.0
 */
@RestController
@RequestMapping("/companys")
public class CompanyController {
    @Autowired
    private CompanyService companyService;

    /**
     * 修改公司信息
     * @param id
     * @param company
     * @return
     */
    @PutMapping("/{id}")
    public String updataCompany(@PathVariable Integer id, @RequestBody Company company){
        //设置id
        company.setId(id);
        //修改企业信息
        companyService.updateById(company);

        return "修改成功";
    }

    /**
     * 全分页查询
     * @param
     * @return
     */
    @GetMapping
    public PageResult pageAll(Integer page,Integer pagesize){
        CompanDto companyDto = new CompanDto();
        companyDto.setPage(page);
        companyDto.setPagesize(pagesize);
        PageResult pageResult = companyService.pageAll(companyDto);

        return pageResult;
    }

    /**
     * 企业管理删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public String deleteById(@PathVariable Integer id){
        companyService.removeById(id);
        return "删除成功";
    }

    /**
     * 企业添加
     * @param company
     * @return
     */
    @PostMapping
    public String addCompany(@RequestBody Company company){
        companyService.save(company);
        return "添加成功";
    }

    /**
     * 修改用户状态
     * @param id
     * @param state
     * @return
     */
    @PostMapping("/{id}/{state}")
    public String updateState(@PathVariable Integer id,@PathVariable Integer state){
        companyService.updateState(id,state);
        return "状态更改成功";
    }

    /**
     * 用户由id获得企业
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Company getById(@PathVariable Integer id){
        Company company = companyService.getById(id);
        return company;
    }

}
